package Controleur;

import gui.ChoixFenetre;
import gui.FenetrePrincipale;
import gui.LoginFenetre;

import java.awt.event.ActionEvent;

import javax.swing.JOptionPane;

/**
 * @author Tristan
 *
 */
public class ControleurGeneral implements AbstractControleur {
	public static final int LOGIN = 100;
	public static final int DEMARRER_RESERVATION = 200;
	public static final int DEMARRER_SEJOUR = 300;
	public static final int DEMARRER_FACTURATION = 400;
	public static final int DEMARRER_MODIFICATION_SEJOUR = 500;
	public static final int CLOSE_FENETRE_CHOIX = 600;	
	
	private FenetrePrincipale fenetreActive;
	private AbstractControleur controleurEnfant;

	
	public void initSysteme(AbstractControleur ctrl) {
		fenetreActive = new LoginFenetre(this);
	}
	
	@Override
	public void reloadCtrl() {
		initSysteme(null);
	}

	/* (non-Javadoc)
	 * @see java.awt.event.ActionListener#actionPerformed(java.awt.event.ActionEvent)
	 */
	@Override
	public void actionPerformed(ActionEvent e) {
		String action = e.getActionCommand();
		switch(Integer.parseInt(action)){ 
			case LOGIN:
				if (((LoginFenetre)fenetreActive).checkLogin()) {
					fenetreActive.close();
					fenetreActive = new ChoixFenetre(this);
				}
				else {	
					//afficher messsage erreur
					JOptionPane.showMessageDialog(null, "Nom ou mot de passe n'est pas valide", "Identification", JOptionPane.ERROR_MESSAGE);
					((LoginFenetre)fenetreActive).viderChamps();
				}
				break;
			case DEMARRER_RESERVATION:
				fenetreActive.close();
				controleurEnfant = new ControleurReservation();
				controleurEnfant.initSysteme(this);
				break;
			case DEMARRER_SEJOUR:
				fenetreActive.close();
				controleurEnfant = new ControleurSejour();
				controleurEnfant.initSysteme(this);
				break;
			case DEMARRER_FACTURATION:
				fenetreActive.close();
				controleurEnfant = new ControleurFacture();
				controleurEnfant.initSysteme(this);
				break;
			case DEMARRER_MODIFICATION_SEJOUR:
				fenetreActive.close();
				controleurEnfant = new ControleurChangerChambre();
				controleurEnfant.initSysteme(this);
				break;
			case CLOSE_FENETRE_CHOIX:
				fenetreActive.close();
				initSysteme(null);
				break;
		}
	}
}
